import React, { Component } from 'react';
import { View, Text, StyleSheet, PixelRatio, Image } from 'react-native';
import { GLOBAL } from '../../../config/global';
import { style } from '../../../theme/style';
import { Common } from '../../../component/common/Common.js';
import { currency, saleTag, purchaseTag, betweenLayout } from '../create/_components/common';

const scale = GLOBAL.SCALE;
export class ProductItemDetail extends Component {
	static navigationOptions = ({ navigation, navigationOptions }) => {
		return {
			headerTitle: '商品详情',
			headerTintColor: style.color.white,
			headerLeft: <Common type="headLeft" onPress={() => { navigation.goBack(); }} color='#fff' />,
			headerRight: null,
			headerStyle: style.head.headerStyle,
			headerTitleStyle: {
				flex: 1,
				textAlign: 'center'
			},
			gesturesEnabled: false  //禁止侧滑返回事件
		}
	};
	constructor(props) {
		super(props);
	}

	render() {
		const { item, isEdit, tCode } = this.props.navigation.state.params;
		return (
			<View style={styles.border}>
				{betweenLayout('商品名', item.goodsName)}
				{betweenLayout('采购量', `${item.quantity} 吨`)}

				{item.baseDateSettleName ? betweenLayout('基准日', item.baseDateSettleName) : null}
				{item.nakedPrice ? betweenLayout(item.priceType == 2 ? '暂定价' : '一口价', `${item.nakedPrice} 美元/吨`, { tag: tCode === 'SINONEWC' ? purchaseTag : null }) : null}
				{item.nakedSalePrice ? betweenLayout(item.priceType == 2 ? '暂定价' : '一口价', `${item.nakedSalePrice} 美元/吨`, { tag: tCode === 'SINONEWC' ? saleTag : null }) : null}
				{item.priceFormulaDesc ? betweenLayout('结算价公式', item.priceFormulaDesc) : null}
				{this.isAdjust || item.resv3 ?
					<View style={{ flexDirection: 'row', alignItems: 'center' }}>
						<Text style={styles.inputKey}>结算价</Text>
						<TextInput value={item.resv3} onChangeText={(text) => {
							item.resv3 = text;
							this.setState({ ls: true })
						}} keyboardType='numeric' editable={isEdit} style={[styles.inputStyle, isEdit ? styles.inputBorder : null]} />
					</View>
					: null}
				{item.udPrice ? betweenLayout(item.udPrice > 0 ? '升水' : '贴水', Math.abs(item.udPrice)) : null}
				{(item.dutyRate || item.dutyRate == 0) ? betweenLayout('关税', `${item.dutyRate}%`) : null}
				{(item.vatRate || item.vatRate == 0) ? betweenLayout('增值税', `${item.vatRate}%`) : null}
			</View>
		)
	}
}
const styles = StyleSheet.create({
	border: {
		// borderBottomWidth: 1 / PixelRatio.get(),
		// borderStyle: 'solid',
		// borderBottomColor: '#E3E7F0',
		paddingTop: 20 * scale,
		paddingBottom: 13 * scale
	},
	inputKey: {
		width: 75 * scale,
		marginLeft: 24 * scale,
		height: 30 * scale,
		lineHeight: 30 * scale,
		textAlign: 'right',
		marginRight: 30 * scale,
		fontSize: 14 * scale,
		paddingLeft: 0 * scale,
		color: '#000000'
	},
	inputStyle: {
		height: 25 * scale,
		width: 120 * scale,
		paddingRight: 5 * scale,
		fontSize: 14 * scale,
		fontWeight: 'bold',
		color: '#000',
		paddingVertical: 0
	},
	inputBorder: {
		borderWidth: 1 / PixelRatio.get(),
		borderStyle: 'solid',
		borderColor: '#0E7FFD',
		paddingLeft: 5 * scale
	}
})